package com.bl.weilan.manager.controller.companypoint;

import com.bl.weilan.common.ApiResponseBody;
import com.bl.weilan.dao.model.CompanyPointEntity;
import com.bl.weilan.manager.controller.BaseController;
import com.bl.weilan.service.biz.companypoint.CompanyPointService;
import com.bl.weilan.service.vo.DelBody;
import com.bl.weilan.service.vo.DelListBody;
import com.bl.weilan.service.vo.companypoint.CompanyPointAddVo;
import com.bl.weilan.service.vo.companypoint.CompanyPointListVo;
import com.bl.weilan.service.vo.companypoint.CompanyPointModVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;


@RestController
@Log4j2
@RequestMapping(value = {"/weilan/manager/point"})
@Api(value = "综合评分相关", description = "综合评分相关api")

public class CompanyPointController extends BaseController {
    @Autowired
    CompanyPointService companypointService;

    @ApiOperation(value = "获取公司综合评分列表信息", notes = "获取公司综合评分列表信息")
    @ApiImplicitParams({
             @ApiImplicitParam(name = "page", value = "页数", required = false, paramType = "query", dataType = "int", defaultValue = "1"),
            @ApiImplicitParam(name = "size", value = "每页大小", required = false, paramType = "query", dataType = "int", defaultValue = "10")})
    @GetMapping(value = {"/get_list"})
    public ApiResponseBody<CompanyPointListVo> companypointList(
             @RequestParam(value = "page", required = false, defaultValue = "1") int page,
            @RequestParam(value = "size", required = false, defaultValue = "10") int size,
            HttpServletRequest request) {

        Pageable pageable = new PageRequest(page - 1, size);

        CompanyPointListVo companypointListVo = companypointService.getCompanyPointLists(pageable);

        return ApiResponseBody.createSuccessBody(companypointListVo);
    }
//
//    @ApiOperation(value = "根据公司id获取公司综合评分信息", notes = "根据公司id获取公司综合评分信息")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "query", dataType = "String")})
//    @GetMapping(value = {"/get_detail"})
//    public ApiResponseBody<CompanyPointListVo> companypointList(
//            @RequestParam(value = "id", required = true) String id,
//            HttpServletRequest request) {
//
//        CompanyPointEntity companypointEntity = companypointService.getCompanyPointById(id);
//
//        return ApiResponseBody.createSuccessBody(companypointEntity);
//    }

    @ApiOperation(value = "增加一家公司的综合评分信息", notes = "增加一家公司的综合评分信息 ")
    @ApiImplicitParams({})
    @PostMapping(value = {"/add"})
    public ApiResponseBody add(
            @Valid @RequestBody CompanyPointAddVo body, BindingResult result,
            HttpServletRequest request) {

        ApiResponseBody validResult = validParams(result);
        if (validResult != null) {
            return validResult;
        }

        companypointService.addCompanyPoint(body);

        return ApiResponseBody.createSuccessBody(null);
    }

    @ApiOperation(value = "删除批量", notes = "删除批量 ")
    @ApiImplicitParams({
    })
    @PostMapping(value = {"/del_list"})
    public ApiResponseBody delList(
            @Valid @RequestBody DelListBody body, BindingResult result,
            HttpServletRequest request) {

        companypointService.delList(body);

        return ApiResponseBody.createSuccessBody(null);
    }

    @ApiOperation(value = "删除一家公司的综合评分信息", notes = "删除一家公司的综合评分信息 ")
    @ApiImplicitParams({
    })
    @PostMapping(value = {"/del"})
    public ApiResponseBody del(
            @Valid @RequestBody DelBody body, BindingResult result,
            HttpServletRequest request) {


        companypointService.del(body);

        return ApiResponseBody.createSuccessBody(null);
    }

    @ApiOperation(value = "修改一家公司的综合评分信息", notes = "修改一家公司的综合评分信息 ")
    @ApiImplicitParams({})
    @PostMapping(value = {"/modify"})
    public ApiResponseBody modify(
            @Valid @RequestBody CompanyPointModVo body, BindingResult result,
            HttpServletRequest request) {

        ApiResponseBody validResult = validParams(result);
        if (validResult != null) {
            return validResult;
        }

        companypointService.modify(body);

        return ApiResponseBody.createSuccessBody(null);
    }
}
